package com.example.demo2.controller;

import com.example.demo2.entity.Student;
import com.example.demo2.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/{id}")
    public Student findById(@PathVariable Integer id) {
        return studentService.findById(id);
    }

    @PutMapping("/{id}")
    public Student update(@PathVariable Integer id,@RequestBody Student student) {
        student.setId(id);
        return studentService.update(student);
    }

    @PostMapping
    public Student insert(@RequestBody Student student) {
        return studentService.insert(student);
    }

    @DeleteMapping
    public void delete(@PathVariable Integer id) {
        studentService.deleteById(id);
    }

}
